package com.kuqi.entity;

import net.minidev.json.JSONObject;

import javax.persistence.*;
import java.sql.Date;
import java.util.Base64;

@Entity
@Table(name = "books")
public class BookInfo {

    // uuid
    @Id
    private int id;

    // 书名
    @Column(name = "book_name")
    private String bookName;

    // 缩略封面图
    @Column(name = "thumbnail")
    private String thumbnail;

    // 描述简介
    @Column(name = "describe")
    private String describe;

    // 作者
    @Column(name = "author")
    private String author;

    // 书籍类别
    @Column(name = "book_type")
    private int bookType;

    // 书籍上传时间
    @Column(name = "update_date")
    private Date updateDate;


    public BookInfo(){}

    public BookInfo(int id, String bookName, String thumbnail, String describe, String author, int bookType, Date updateDate) {
        this.id = id;
        this.bookName = bookName;
        this.thumbnail = thumbnail;
        this.describe = describe;
        this.author = author;
        this.bookType = bookType;
        this.updateDate = updateDate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getThumbnail() {
        return thumbnail;
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getBookType() {
        return bookType;
    }

    public void setBookType(int bookType) {
        this.bookType = bookType;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    //数据转为json字符串并返回
    public String toJsonString(){
        return this.toJsonObject().toJSONString();
    }

    //转为Object对象
    public JSONObject toJsonObject()
    {
        JSONObject result = new JSONObject();
        result.put("id", id);
        result.put("bookName", bookName);
        result.put("thumbnail", thumbnail);
        result.put("describe", describe);
        result.put("author", author);
        result.put("bookType", bookType);
        result.put("updateDate", updateDate.toString());
        return result;
    }

}